<div class="xf_ht_jr_obu_width">
  <div class="xf_fktz_tcc_table">
  <table border="0" cellspacing="0" cellpadding="0" class="xf_ht_jr_obu_form">
    <tr>
      <td align="right" width="140">管理员账号：</td>
      <td><input class="xf_ht_jr_dfk_i_input" type="text" value="系统自动分配" readonly ></td>
    </tr>
    <tr>
      <td align="right" valign="middle" class="xf_ht_jr_obttd_l">管理员等级：</td>
      <td><select name="select" id="level" class="xf_ht_jr_dfk_i xf_ht_jr_dfk_i2">
          <option value="0" selected="selected">普通管理员</option>
          <option value="1">超级管理员</option>
      </select></td>
    </tr>
    <tr>
      <td align="right" width="140">权限组：</td>
      <td><input type="button" onclick="selectGroupsOfSupervisorInit(1, 3);" value="设置权限组" class="xf_ht_tcc_zzezat2" id="xf_dfk_fkzh_tcc10"></td>
    </tr>
    <tr>
      <td align="right" width="140">真实姓名：</td>
      <td><input id="realityName" class="xf_ht_jr_dfk_i_input" type="text"></td>
    </tr>
    <tr>
      <td width="132" align="right" valign="middle"
        class="xf_ht_jr_obttd_l">性别：</td>
      <td><select name="select" id="sex" class="xf_ht_ptgl_dfk_i">
          <option value="1">男</option>
          <option value="2">女</option>
          <option value="3" selected="selected">保密</option>
      </select></td>
    </tr>
    <tr>
      <td align="right" width="140">出生日期：</td>
      <td> 
        <input id="birthday" class="Wdate" style="cursor:pointer" type="text" onclick="laydate()"/> 
      </td>
    </tr>
    <tr>
      <td align="right" width="140">手机1：</td>
      <td><input id="mobile1" class="xf_ht_ptgl_dfk_i" type="text"></td>
    </tr>
    <tr>
      <td align="right" width="140">手机2：</td>
      <td><input id="mobile2" class="xf_ht_ptgl_dfk_i" type="text"></td>
    </tr>
    <tr>
      <td align="right" width="140">邮箱：</td>
      <td><input id="email" class="xf_ht_ptgl_dfk_i" type="text"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="xf_ht_tcc_button">
        <input class="jbox_ok" type="button" value="确  定" onclick="createSupervisor();">
        <input class="jbox_on" type="button" value="取  消" onclick="layer.closeAll()">
      </td>
    </tr>
  </table>
</div>
</div>
<script type="text/javascript">
  var g_groupIds;
  var g_selectedIds;
  
  $(function() {
    //关闭
    $(".xf_ht_jr_obu_r").click(function() {
      $("#xf_ht_tjgly_ttc").hide();
    });

    init();

  });

  //初始化
  function init() {
    g_groupIds = new Array();
    g_selectedIds = new Array();
  }
  
  //设置权限组
  function selectGroupsOfSupervisorInit(currPage, pageSize) {
    $.ajax({
      url : "@{selectGroupsOfSupervisorInit()}",
      type : "POST",
      data : {
        "currPage" : currPage,
        "pageSize" : pageSize
      },
      success : function(data) {
        if (data.code < 0) {
          alert(data.msg);
          
          return;
        }
        
        if(p2p >=2 && p2p!=ps) {
          layer.close(p2p);
        }
        
        var ttc = $("#xf_ht_szqxz_ttc");
        ttc.html(data);
        p2p = $.layer({
                  type: 1,
                  area: ['800', 'auto'],
                  title: '设置权限组员',
                  page: {dom : ttc},
                  end:function() {
                    if(p2p >2) {
                      layer.close(p2p);
                    }
                    
                  }
                  
        });
      },
      error : function() {
        alert("对不起，出现错误!");
      }
      
    });
    
  }
  
  //权限组选择完毕
  function groupsDidSelect(groupIds) {
    g_groupIds = clone(groupIds);
  }
  
  //确定(添加管理员)
  function createSupervisor() {
    var level = $("#level").val()
    var groupIds = g_groupIds.join(",");
    var realityName = $("#realityName").val().trim();
    
    if ("" == realityName) {
      alert("请输入真实姓名");
      $("#realityName").focus();
      
      return;
    }

    if (realityName.length > 50) {
        alert("真实姓名长度需在0~50之间");
        $("#realityName").focus();
        
        return;
      }
    
    var sex = $("#sex").val();
    var birthday = $("#birthday").val().trim();
    
    if ("" == birthday) {
      alert("请输入出生日期");
      $("#birthday").focus();
      
      return;
    } else if (!birthday.isDate()) {
      alert("出生日期格式不正确，正确的格式如：2008-08-08");
      $("#birthday").focus();
      
      return;
    }
    
    var mobile1 = $("#mobile1").val().trim();
    
    if ("" == mobile1) {
      alert("请输入手机1");
      $("#mobile1").focus();
      
      return;
    } else if (!mobile1.isMobileNum()) {
      alert("手机1格式不正确，请重新输入");
      $("#mobile1").focus();
      
      return;
    }
    
    var mobile2 = $("#mobile2").val().trim();
    
    if ("" != mobile2 && !mobile2.isMobileNum()) {
      alert("手机2格式不正确，请重新输入");
      $("#mobile2").focus();
      
      return;
    }
    
    var email = $("#email").val().trim();
    
    if ("" == email) {
      alert("请输入邮箱");
      $("#email").focus();
      
      return;
    } else if (!email.isEmail()) {
      alert("邮箱格式不正确，请重新输入");
      $("#email").focus();
      
      return;
    }
    
    $.ajax({
      url : "@{createSupervisor()}",
      type : "POST",
      data : {
        "level" : level,
        "groupIds" : groupIds,
        "realityName" : realityName,
        "sex" : sex,
        "birthday" : birthday,
        "mobile1" : mobile1,
        "mobile2" : mobile2,
        "email" : email
      },
      success : function(data) {
        alert(data.msg);
        
        if (data.code == 0) {
          location.reload();
        }
      },
      error : function() {
        alert("对不起，出现错误!");
      }
    });
  }
  
</script>